
//
//  GFLcViewController.m
//  Qyer
//
//  Created by dlios on 15/10/22.
//  Copyright (c) 2015年 GF. All rights reserved.
//

#import "GFLcViewController.h"

@interface GFLcViewController ()

@end

@implementation GFLcViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _tableArray = [NSMutableArray array];
    [self getAfn];
    _temp = 1;
    _table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    [_table setDelegate:self];
    [_table setDataSource:self];
    [self.view addSubview:_table];
    [self getAfn];
    [_table addLegendFooterWithRefreshingTarget:self refreshingAction:@selector(addFooter)];
}

- (void)addFooter{
    ++_temp;
    [self getAfn];
}

- (void)getAfn{
    NSString *comString = [NSString stringWithFormat:@"%@%ld", _afnString, _temp];
    [AFN getdataWithString:comString block:^(id block) {
        for (NSDictionary *dic in block) {
            GFJnModel *model = [GFJnModel modelWithDictionary:dic];
          model.height = [StringWithHeight HeightWithText:model.description width:SCREEN_WIDTH - 10 * WIDTH font:[UIFont systemFontOfSize:WIDTH * 16.]];
            [_tableArray addObject:model];
        }
        [_table reloadData];
        [_table.header endRefreshing];
        [_table.footer endRefreshing];
    } BLOCK:^(id BLOCK) {
        
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _tableArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    GFJnModel *model = [_tableArray objectAtIndex:indexPath.row];
    return 160 * HEIGHT + model.height;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *guoFeng = @"cell";
    GFLcTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:guoFeng];
    if (!cell) {
        cell = [[GFLcTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:guoFeng];
    }
        GFJnModel *model = [_tableArray objectAtIndex:indexPath.row];
        [cell getJnModel:model];
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
